package shujujiegou;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.junit.Test;


public class TestDB {
	
	
	
	
	public static void main(String[] args) {
		String url = "jdbc:oracle:thin:@192.168.8.233:1521:hzsmdb";
		String user = "hzsmdb";
		String password = "hzsm#DB";
		
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
			Connection conn = DriverManager.getConnection(url, user, password);
			if(conn != null) {
				System.out.println("connection success");
			} else {
				System.out.println("connection error");
			}
			String sql = "insert into ABC_DAILY_INCOME_CHECK values('1','2',3,4,5,6,7,8,9,10,11,12)";
			Statement st = conn.createStatement();
			int count = st.executeUpdate(sql);
			
			System.out.println("count:"+count);
			
			
			
			
			
			conn.close();
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
		
		
	}
	
	@Test
	public void testSelectDB(){
		String url = "jdbc:oracle:thin:@192.168.8.233:1521:hzsmdb";
		String user = "hzsmdb";
		String password = "hzsm#DB";
		
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
			Connection conn = DriverManager.getConnection(url, user, password);
			if(conn != null) {
				System.out.println("connection success");
			} else {
				System.out.println("connection error");
			}
			String sql = "select * from ABC_DAILY_INCOME_CHECK";
			Statement st = conn.createStatement();
			ResultSet rs = st.executeQuery(sql);
			while(rs.next()) {
				String INS_DATE = rs.getString(1).trim();
				String COMPANY = rs.getString(2).trim();
				int INIT_AMT = rs.getInt(3);
				int INIT_IN_TRAN_FUND = rs.getInt(4);
				int INIT_RECV = rs.getInt(5);
				int BANK_RECV_AMT = rs.getInt(6);
				int BANK_BACK_TRAN = rs.getInt(7);
				int CARD_SELL_AMT = rs.getInt(8);
				int PRE_ADJ_CARD_SELL_AMT = rs.getInt(9);
				int TERM_AMT = rs.getInt(10);
				int TERM_IN_TRAN_FUND = rs.getInt(11);
				int TERM_RECV = rs.getInt(12);
				System.out.println(INS_DATE+","+COMPANY+","+INIT_AMT
						+","+INIT_IN_TRAN_FUND+","+INIT_RECV+","+BANK_RECV_AMT
						+","+BANK_BACK_TRAN+","+CARD_SELL_AMT+","+PRE_ADJ_CARD_SELL_AMT
						+","+TERM_AMT+","+TERM_IN_TRAN_FUND+","+TERM_RECV);
			}
			
			
			
			
			
			conn.close();
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
		
		
	}
	
	
	
	
	
	
}
